<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <div class="nav nav-tabs">
        <h4>数据统计</h4>
    </div>
    <form class="well form-inline margin-top-20" method="post" action="">
        时间:
        <input type="text" class="form-control js-bootstrap-date" name="start_time" id="start_time"
               value="{$where_r.start_time|default=''}"
               style="width: 140px;" autocomplete="off">-
        <input type="text" class="form-control js-bootstrap-date" name="end_time" id="end_time"
               value="{$where_r.end_time|default=''}"
               style="width: 140px;" autocomplete="off"> &nbsp; &nbsp;
        分类：
        <select class="form-control" id="industry">
           <option>全部</option>
            <volist name="industry" id="vo">
                <option value="{$vo.id}">{$vo.name}</option>
            </volist>
        </select>&nbsp; &nbsp;
        <input type="button" id="choose_time" class="btn btn-primary" value="筛选"/>

    </form>
    <!--<button>按钮</button>-->
</div>
<div>
    <div id="container" style="width:80%;height:600px; margin: 0 auto"></div>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script src="__STATIC__/js/echarts/echarts.min.js"></script>
<script src="__STATIC__/js/echarts/china.js"></script>
<script>
    $(function () {
        var chart = echarts.init(document.getElementById('container'));
        option = {
            title: {
                text: '卖家区域分布图',
//                subtext: '纯属虚构',
                left: 'center'
            },
            tooltip: {
                trigger: 'item',
                formatter: function (params) {
                    if (params.data && params.data.value) {
                        return params.seriesName + '<br/>' + params.name + ' : ' + params.data.value;
                    } else if (params.data && !params.data.value) {
                        return params.seriesName + '<br/>' + params.name + ' : ' + 0;
                    }
                }
            },
            legend: {
                type: 'scroll',
                orient: 'vertical',
                right: 10,
                top: 20,
                bottom: 20,
                data: []
            },
            visualMap: {
                min: 0,
//                max: 10000,
                left: 'left',
                top: 'bottom',
                text: ['高', '低'],
                calculable: true,
                show: false,
                inRange: {
                    color: ['#e0f3f8', '#ffffbf', '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026']
                }
            },
            toolbox: {
                show: true,
                orient: 'vertical',
                left: 'right',
                top: 'center',
                feature: {
                    dataView: {readOnly: false},
                    restore: {},
                    saveAsImage: {}
                }
            },
            series: [
                {
                    name: '卖家数据',
                    type: 'map',
                    mapType: 'china',
                    roam: false,
                    label: {
                        normal: {
                            show: true
                        },
                        emphasis: {
                            show: true
                        }
                    },
                    data: []
                }
            ]
        };

        function subStr(str) {
            //处理文字不匹配问题
            if (str.substring(str.length - 1, str.length) == "省" || str.substring(str.length - 1, str.length) == "市" || str.substring(str.length - 1, str.length) == "区") {
                return str.substring(0, str.length - 1);
            } else {
                return str;
            }
        }

        function getdata(){
            var params = {
                start_time: $('#start_time').val(),
                end_time: $('#end_time').val(),
                industry: $('#industry').val(),
            };
            option.series[0].data = [];//清空原数据
            $.ajax({
                url: "{:url('getdata')}",
                type: 'post',
                data: params,
                dataType: "json",
                success: function (data) {
                    var sum = 0;
                    var max = 10;
                    $.each(data.data.LicensePlate.data, function (i, e) {
                        option.legend.data.push(e.name);
                        sum += e.count;
                        if(e.count>max)max = e.count;
                        option.series[0].data.push({
                            value: e.count, name: subStr(e.name)
                        });
                    });
                    option.visualMap.max = max;
                    option.title.subtext = "共"+sum+"条数据";
                    chart.setOption(option, true);
                }
            });
        }
        $('#choose_time').click(function () {
            getdata();
        })
        getdata();
        $(window).resize(function () {
            chart.resize();
        });
    });
</script>
</body>
</html>